*************************************************************************
*************************************************************************
****** THIS PROGRAM PRODUCES RESULTS FOR TABLES 4-6 AND APPENDIX 5 ******
*************************************************************************
*************************************************************************

clear  
cd "\\file\UsersW$\wrr15\Home\My Documents\My Files\TAXES AND ECONOMIC GROWTH IN OECD COUNTRIES - A META-ANALYSIS\SUBMISSION TO PFR\DATA AND PROGRAMS"
log using "Part1 Results(20200102).smcl", replace
set more off
set type double 
graph drop _all
import excel "TAX.xlsx", sheet("Stata") firstrow case (lower)
gen endog = (tsls == 1 | gmm == 1)

*---------------------------------------------------------------------*
*   TABLE 4: Distribution of Tax Effects by Fiscal Policy             *
*---------------------------------------------------------------------*
// FULL SAMPLE
summ coefficient if predneg == 1, detail
summ coefficient if predother == 1, detail
summ coefficient if predpos == 1, detail

quietly summ coefficient, detail
scalar low = r(p5)
scalar high = r(p95)
keep if coefficient > low & coefficient < high

// TRUNCATED SAMPLE
summ coefficient if predneg == 1, detail
summ coefficient if predother == 1, detail
summ coefficient if predpos == 1, detail

*-------------------------------------*
*   TABLE 6: Sample Means             *
*-------------------------------------*
summ ///
g7 eu15 eumem oecd ///
gdp pcgdp ///
marginal differenced etr ///
lrcase1 lrcase2 lrcase3 ///
peerreviewed originalpubyear ///
cs panel ///
length originalmidyear ///
ols gls endog ///
seols sehet sehac ///
income laggeddv countryfe investment tradeopenness human popgrowth ///
employgrowth unemploymentrate inflation 

*--------------------------------------------------------------------------------*
*   TABLE 5: First Estimates of Tax Effects                                      *
*--------------------------------------------------------------------------------*

// FIXED EFFECTS

// Generating transformed variables for FE
gen feprecision = 1/se
gen fetstat = coefficient/se
gen prednegg = predneg/se
gen predposs = predpos/se

// TABLE 5/PANEL A
// NO CORRECTION FOR PUBLICATION BIAS
//This regression gives equal weight to each estimate
// TABLE 5 - Panel A/Column 1
regress fetstat feprecision prednegg predposs, noc vce(cluster idstudy)
lincom -prednegg + predposs
//This regression gives equal weight to each study
// TABLE 5 - Panel A/Column 2
regress fetstat feprecision prednegg predposs [pweight = weight], noc vce(cluster idstudy)
lincom -prednegg + predposs

// TABLE 5/PANEL B
// CORRECTION FOR PUBLICATION BIAS
//This regression gives equal weight to each estimate
// TABLE 5 - Panel B/Column 1
regress fetstat feprecision prednegg predposs, vce(cluster idstudy)
lincom -prednegg + predposs
//This regression gives equal weight to each study
// TABLE 5 - Panel B/Column 2
regress fetstat feprecision prednegg predposs [pweight = weight], vce(cluster idstudy)
lincom -prednegg + predposs

// RANDOM EFFECTS

// Generating transformed variables for RE

metareg coefficient peerreviewed pubyear cs length midyear gdp marginal differenced etr  ///
investment tradeopenness human popgrowth employgrowth unemployment inflation income laggeddv ///
countryfe sehac sehet lrcase2 lrcase3 gls endog eu15 g7 eumem ///
labourtax capitaltax othertaxes mixedtaxes overalltax predneg predpos se, wsse(se)
scalar tau2 = e(tau2)
gen revar = se^2 + tau2
gen rese = sqrt(revar)
gen reprecision = 1/rese
gen retstat = coefficient/rese
gen repubbias = se/rese
replace prednegg = predneg/rese
replace predposs = predpos/rese

// TABLE 5/PANEL A
// NO CORRECTION FOR PUBLICATION BIAS
//This regression gives equal weight to each estimate
// TABLE 5 - Panel A/Column 3
regress retstat reprecision prednegg predposs, noc vce(cluster idstudy)
lincom -prednegg + predposs
//This regression gives equal weight to each study
// TABLE 5 - Panel A/Column 4
regress retstat reprecision prednegg predposs [pweight = weight], noc vce(cluster idstudy)
lincom -prednegg + predposs

// TABLE 5/PANEL B
// CORRECTION FOR PUBLICATION BIAS
//This regression gives equal weight to each estimate
// TABLE 5 - Panel B/Column 3
regress retstat reprecision repubbias prednegg predposs, noc vce(cluster idstudy)
lincom -prednegg + predposs
//This regression gives equal weight to each study
// TABLE 5 - Panel B/Column 4
regress retstat reprecision repubbias prednegg predposs [pweight = weight], noc vce(cluster idstudy)
lincom -prednegg + predposs

*----------------------------------------------------------------*
*   APPENDIX 5: Fixed Effects                                    *
*----------------------------------------------------------------*
// Determining the weight of individual studies (Fixed Effects)
preserve
gen fevarR = se^2
gen feweightR = 1/fevarR
gen r = coefficient
gen rR = r*feweightR
collapse (sum) rR feweightR, by (idstudy)
gen avgR = rR/feweightR
gen avgsterrR = sqrt(1/feweightR)
sort idstudy
metan avgR avgsterrR, fixed lcols(id) nobox
gen studyweight = _WT
summ studyweight, detail
gsort -studyweight
// NOTE: The top 3 studies account for approximately 92% of the weight! 
restore

*-----------------------------------------------------------------*
*   APPENDIX 5: Random Effects                                    *
*-----------------------------------------------------------------*
// Determining the weight of individual studies (Random Effects)
gen reweightR = 1/revar
gen r = coefficient
gen rR = r*reweightR
collapse (sum) rR reweightR, by (idstudy)
gen avgR = rR/reweightR
gen avgsterrR = sqrt(1/reweightR)
sort idstudy
metan avgR avgsterrR, random lcols(id) nobox
gen studyweight = _WT
summ studyweight, detail
gsort -studyweight
// NOTE: Random effects very evenly (too evenly?) weighted

log close
